package com.market.fleamarket.repository;

import com.market.fleamarket.entity.Order;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface OrderRepository extends JpaRepository<Order, Long> {
    // 根据买家ID查询订单，并加载关联的Product对象
    @Query("SELECT o FROM Order o LEFT JOIN FETCH o.product WHERE o.buyer.id = :buyerId")
    List<Order> findByBuyerId(@Param("buyerId") Long buyerId);

    // 根据卖家ID查询订单（分页）
    @Query("SELECT o FROM Order o WHERE o.product.user.id = :sellerId")
    Page<Order> findByProductUserId(@Param("sellerId") Long sellerId, Pageable pageable);

    // 可扩展自定义查询
} 